using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Selector
{
    public partial class Selector : UserControl
    {
        public Selector()
        {
            InitializeComponent();

            this.mRandom = new Random(); 
            mPreviousMouseLocation = new Point();
            mMouseDelta = new Point();
        }

        private System.Random mRandom;

        private bool mResizing;
        private bool mDragging;
        
        private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
        {
            this.mResizing = true;
        }

        private void pictureBox3_MouseUp(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.DarkGreen;
            this.mResizing = false;
        }

        private void pictureBox3_MouseMove(object sender, MouseEventArgs e)
        {
            //this.BackColor = Color.FromArgb(this.mRandom.Next(1, 255), this.mRandom.Next(1, 255), this.mRandom.Next(1, 255));

            if (this.mResizing)
            {
                this.Width = e.X - this.Location.X;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Width++;
        }

        private void Selector_MouseDown(object sender, MouseEventArgs e)
        {
            this.mDragging = true;

            mPreviousMouseLocation = e.Location;
        }


        private void Selector_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.mDragging)
            {
                Point newLocation = new Point();

                mMouseDelta.X = e.Location.X - mPreviousMouseLocation.X;
                mMouseDelta.Y = e.Location.Y - mPreviousMouseLocation.Y;
                mPreviousMouseLocation = e.Location;


                newLocation.X += mMouseDelta.X;
                newLocation.Y += mMouseDelta.Y;

                this.Location = newLocation;
                //this.Width = e.X - this.Location.X;
            }
        }

        private void Selector_MouseUp(object sender, MouseEventArgs e)
        {
            this.mDragging = false;
        }

        private Point mPreviousMouseLocation;
        private Point mMouseDelta;
    }
}